/**
*  \file trilean.h
*
*  \brief Three Value Logic
*
*  \author Michael J. Hohmann  michael.hohmann@linde-mh.de
*
*/
#ifndef TRILEAN_H_INCLUDED
#define TRILEAN_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"

/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/
/** Three Value Logic enumumerator
*
*  The enum provides 3 values to use as three value logic.
*/
enum trilean
{
	trilean_true 	=  1, /**< True value 			*/
	trilean_unknown =  0, /**< Unknown or invalid 	*/
	trilean_false	= -1  /**< False Value			*/
};

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/


/** Tree Value Logic NOT
*
* 	 |  NOT   | Result|
*    |--------|-------|
*    |False   |   T   |
*    |Unknown |   U   |
*    |True    |   F   |
*
*  \param [in] a Value to be inverted
*
*  \return The inverted value of a
*
*/
STATIC_INLINE enum trilean trilean_not( enum trilean a )
{
	if( a == trilean_true)
	{
		return trilean_false;
	}

	if( a == trilean_false)
	{
		return trilean_true;
	}

	return trilean_unknown;
}


/** Tree Value Logic AND
*
* 	 |AND     | False | Unknown | True |
*    |--------|-------|---------|-------
*    |False   |   F   |    F    | F    |
*    |Unknown |   F   |    U    | U    |
*    |True    |   F   |    U    | T    |
*
*  \param [in] a value to ADD with parameter b.
*  \param [in] b value to ADD with parameter a.
*
*  \return The value of a AND b
*/
STATIC_INLINE enum trilean trilean_and( enum trilean a, enum trilean b )
{
	if(( trilean_true == a ) && ( trilean_true == b ))
	{
		return trilean_true;
	}
	if(( trilean_false == a ) || ( trilean_false == b ))
	{
		return trilean_false;
	}

	return trilean_unknown;
}

/** Tree Value Logic OR
*
* 	 | OR     | False | Unknown | True |
*    |--------|-------|---------|-------
*    |False   |   F   |    U    |  T   |
*    |Unknown |   U   |    U    |  T   |
*    |True    |   T   |    T    |  T   |
*
*  \param [in] a value to OR with parameter b.
*  \param [in] b value to OR with parameter a.
*
*  \return The value of a OR b

*/
STATIC_INLINE enum trilean trilean_or( enum trilean a, enum trilean b )
{
	if(( trilean_false == a ) && ( trilean_false == b ))
	{
		return trilean_false;
	}

	if(( trilean_true == a ) || ( trilean_true == b ))
	{
		return trilean_true;
	}

	return trilean_unknown;
}

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2019 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
